<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />

    <div style="height: 47px"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <el-button @click="closeDrawer(1)">取 消</el-button>
      <!-- <el-button @click="closeDrawer(2)" type="primary">确 定</el-button> -->
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">确 定</multiuse-button>
    </div>
  </div>
</template>
<script>
  import { assignBatchTarget } from '@/api/omSale/salesPlan/MonthTargetQuery';
  export default {
    props: {
      targetSource: {
        type: Number,
        required: true
      },
    },
    data() {
      this.saveData = null;
      return {
        formList: this.createdFrom(),
      };
    },
    components: {},
    // props: ['list'],
    methods: {
      createdFrom() {
        return [
          {
            type: 'DATE',
            label: '指标月份',
            fieldName: 'targetDate',
            placeholder: '请输入',
            selfCols: 2,
            dateType: 'month',
            rules: [{ required: true, message: '请输入', trigger: 'blur' }],
          },
        ];
      },
      changeHandle(val) {
        this.saveData = val;
      },
      async closeDrawer(type) {
        if (type == 1) {
          this.$emit('close');
        } else {
          this.$refs.from.SUBMIT_FORM();
          if (this.saveData) {
            this.saveData['targetSource'] = this.targetSource
            console.log(this.saveData,'---------------------')
            let res = await assignBatchTarget(this.saveData);
            if (res.resultCode == 200) {
              this.$notify({
                title: res.data,
                message: res.errMsg,
                type: 'success',
              });
              this.$emit('close');
            } else {
              this.saveData = null;
            }
          }
        }
      },
    },
  };
</script>
